package com.example.dormlist.security;

import com.example.dormlist.appuser.AppUserService;
import com.example.dormlist.security.filter.CustomAuthorizationFilter;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@Configuration
@EnableWebSecurity
@AllArgsConstructor
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    private final AppUserService appUserService;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
//        CustomAuthenticationFilter authenticationFilter = new CustomAuthenticationFilter(authenticationManagerBean(), appUserService);
//        authenticationFilter.
        http
                .csrf().disable()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .authorizeRequests().antMatchers("/list").authenticated()
                .anyRequest().permitAll()
                .and()
//                .addFilterBefore(new CustomAuthorizationFilter(appUserService), UsernamePasswordAuthenticationFilter.class)
        ;
    }



}
